home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-27 | 5.2 KB | 216 lines | [TEXT/SPM ] |
- //• Helper.c - from Solver 1.1 ©1995 by Stefan C. Sinclair. All Rights Reserved.
-
- #include <limits.h>
-
- #define kBaseResID 128
- #define kMoveToFront (WindowPtr)-1L
- #define kScrollBarWidth 16
- #define kNilActionProc nil
- #define kSleep LONG_MAX
-
- #define kVisible true
- #define kStartValue 1
- #define kMinValue 1
- #define kNilRefCon 0L
- #define kEmptyTitle "\p"
-
- #define kEmptyString "\p"
- #define kNilFilterProc nil
-
- #define kErrorAlertID kBaseResID
-
-
- /**************/
- /* Globals */
- /**************/
-
- Boolean ggDone;
- ControlActionUPP gActionUPP; //• This is for PowerPC!
- extern Rect helpRect;
- extern PicHandle helpPicture;
- extern WindowPtr hwindow;
-
-
- /* Function Prototypes */
- void Helper( void );
- void HelpWindowInit( void );
- void SetUpScrollBar( WindowPtr window );
- pascal void ScrollProc( ControlHandle theControl, short partCode );
- void HelpEventLoop( void );
- void HelpDoEvent( EventRecord *eventPtr );
- void HelpHandleMouseDown( EventRecord *eventPtr );
- void HelpUpdateWindow( WindowPtr window );
-
- //• The main online help routine; resembles a mini-application.
- void Helper(void)
- {
- HelpWindowInit();
- HelpEventLoop();
- HideWindow(hwindow);
- }
-
- //• HelpWindowInit() - actually, the window has already been initialized. Here, we just bring it to the front.
- void HelpWindowInit(void)
- {
- ShowWindow( hwindow );
- SetPort( hwindow );
- }
-
-
- /********************************** SetUpScrollBar *******/
- void SetUpScrollBar( WindowPtr window )
- {
- Rect vScrollRect;
- short numViews = 4; //• I have chosen to divide the big PICT into 4 sections here.
- ControlHandle scrollBarH;
-
- vScrollRect = window->portRect;
- vScrollRect.top -= 1;
- vScrollRect.bottom += 1;
- vScrollRect.left = vScrollRect.right - kScrollBarWidth + 1;
- vScrollRect.right += 1;
-
- scrollBarH = NewControl( window, &vScrollRect,
- kEmptyTitle, kVisible, kStartValue, kMinValue,
- numViews, scrollBarProc, kNilRefCon );
- }
-
- //• ScrollProc(); when scrolling, the entire picture is still being drawn, but only 1/4
- //• of it will be visible through the help window. This is achieved by offsetting the help
- //• PICT's rect by 1/4 of it's height each time the scroll bar is hit.
- pascal void ScrollProc( ControlHandle theControl, short partCode )
- {
- short curCtlValue, maxCtlValue, minCtlValue;
- WindowPtr window;
-
- maxCtlValue = GetCtlMax( theControl );
- curCtlValue = GetCtlValue( theControl );
- minCtlValue = GetCtlMin( theControl );
-
- window = (**theControl).contrlOwner;
-
- switch ( partCode )
- {
- case inPageDown:
- case inDownButton:
- if ( curCtlValue < maxCtlValue )
- {
- curCtlValue += 1;
- SetCtlValue( theControl, curCtlValue );
- helpRect.top-=205; // 1/4 of my PICT's height
- helpRect.bottom-=205;
- HelpUpdateWindow( window );
- }
- break;
- case inPageUp:
- case inUpButton:
- if ( curCtlValue > minCtlValue )
- {
- curCtlValue -= 1;
- SetCtlValue( theControl, curCtlValue );
- helpRect.top+=205; // 1/4 of my PICT's height
- helpRect.bottom+=205;
- HelpUpdateWindow( window );
- }
- }
- }
-
- //• HelpEventLoop(); an event loop inside of an event loop.
- void HelpEventLoop(void)
- {
- EventRecord event;
-
- ggDone = false;
-
- while ( ggDone == false )
- {
- if ( WaitNextEvent( everyEvent, &event, kSleep, nil ) )
- HelpDoEvent( &event );
- }
- }
-
- //• HelpDoEvent() - user's actions are pretty limited while in the online help window, as you will see.
- void HelpDoEvent( EventRecord *eventPtr )
- {
- WindowPtr window;
-
- switch ( eventPtr->what )
- {
- case mouseDown:
- HelpHandleMouseDown( eventPtr );
- break;
- case updateEvt:
- window = (WindowPtr)eventPtr->message;
-
- BeginUpdate( window );
- DrawControls( window );
- HelpUpdateWindow( window );
- EndUpdate( window );
- break;
- }
- }
-
- //• HelpHandleMouseDown() - user's actions are pretty limited while in the online help window, as you will see.
- void HelpHandleMouseDown(EventRecord *eventPtr)
- {
- WindowPtr window;
- short thePart;
- Point thePoint;
- ControlHandle theControl;
-
- thePart = FindWindow( eventPtr->where, &window );
- switch ( thePart )
- {
- case inSysWindow :
- SystemClick( eventPtr, window );
- break;
- case inDrag :
- DragWindow( window, eventPtr->where, &qd.screenBits.bounds );
- break;
- case inContent:
- thePoint = eventPtr->where;
- GlobalToLocal( &thePoint );
-
- thePart = FindControl( thePoint, window, &theControl );
- //• Check for scroll bar event
- if ( theControl == ((WindowPeek)window)->controlList )
- {
- if ( thePart == inThumb )
- {
- thePart = TrackControl( theControl, thePoint, kNilActionProc );
- InvalRect( &(window->portRect) );
- }
- else
- {
- gActionUPP = NewControlActionProc( ScrollProc ); //• PPC again!
- thePart = TrackControl( theControl, thePoint, gActionUPP );
- }
- }
- break;
- case inGoAway: //• Leave help now?
- if(TrackGoAway(window, eventPtr->where))
- ggDone = true;
- break;
- }
- }
-
- //• HelpUpdateWindow() - basically just redraws the tall hel PICT
- void HelpUpdateWindow(WindowPtr window)
- {
- Rect windowRect;
- RgnHandle tempRgn;
-
- tempRgn = NewRgn();
- GetClip( tempRgn );
-
- windowRect = window->portRect;
- windowRect.right -= kScrollBarWidth;
- EraseRect( &windowRect );
-
- ClipRect( &windowRect );
-
- DrawPicture( helpPicture, &helpRect );
-
- SetClip( tempRgn );
- DisposeRgn( tempRgn );
- }